@extends('backstage.layout.master')
@section('title', '推广绑定列表')
@section('content')
    <style>
        .state li {
            list-style: none;
            float: left;
            padding: 0 20px;
            text-align: center;
            height: 40px;
            line-height: 40px;
        }

        .state ul {
            margin: 0;
        }

        .state a {
            font-size: 12px;
        }
        .che a {
            font-weight: bold;
            color: #7c7c7c;
        }
    </style>
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="/backstage/promo">推广</a>
            </li>
            <li>
                推广列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                推广
                <small>
                    <i class="icon-double-angle-right"></i>
                    推广列表
                </small>
                <span class="pull-right">
                    <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/promo/promo-res-detail?id={{empty($_GET['id'])?0:$_GET['id']}}';">推广绑定修改</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="alert alert-info">
                    <i class="icon-hand-right"></i>
                    <!-- 信息-->
                    优惠类型为产品时，优惠资源名，'>'前面为品牌名，后面为产品名
                </div>
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th >编号</th>
                            <th >推广编号</th>
                            <th >优惠资源Id</th>
                            <th >优惠资源名</th>
                            <th>优惠类型</th>
                            <th>创建时间</th>
                            <th>更新时间</th>
                            <th width="150px">操作区</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($promo_res as $promo_re)
                        <tr class="" data-tr-id="{{isset($promo_re->id)?$promo_re->id:''}}">
                            <td>
                                {{isset($promo_re->id)?$promo_re->id:''}}
                            </td>
                            <td>
                                {{isset($promo_re->promo_id)?$promo_re->promo_id:''}}
                            </td>
                            <td>
                                {{isset($promo_re->resource_id)?$promo_re->resource_id:''}}
                            </td>
                            <td>
                                {{isset($promo_re->res_name)?$promo_re->res_name:''}}
                            </td>
                            <td>
                                @if(isset($promo_re->type)&&$promo_re->type==0)
                                 全部
                                @elseif(isset($promo_re->type)&&$promo_re->type==1)
                                 产品
                                @elseif(isset($promo_re->type)&&$promo_re->type==2)
                                 作品
                                @elseif(isset($promo_re->type)&&$promo_re->type==3)
                                 品牌
                                @endif
                            </td>
                            <td>
                                {{isset($promo_re->created_at)?date('Y-m-d H:i:s',$promo_re->created_at):""}}
                            </td>
                            <td>
                                {{isset($promo_re->updated_at)?date('Y-m-d H:i:s',$promo_re->updated_at):''}}
                            </td>
                            <td class="center" style="padding-top: 15px">
                                <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                    <a class="deletechannel" title="删除" style="color:#d77600;cursor: pointer;" onclick="deletePromoRes({{$promo_re->id}})">
                                        <i class="icon-trash bigger-130"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $promo_res->render(); ?>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12">
                    <h3 class="header smaller lighter red">注意：</h3>
                    <div class="well red">
                        <h4 class="green smaller lighter">推广简介:</h4>
                        1、推广Id：{{isset($promo->promo_id)?$promo->promo_id:""}}</br>
                        2、推广名称：{{isset($promo->promo_name)?$promo->promo_name:""}}</br>
                        3、推广简介：{{isset($promo->promo_name)?$promo->promo_name:""}}</br>
                        @if(isset($promo->type)&&($promo->type==2))
                        4、当前推广按结算订单成交金额结算</br>
                        @endif
                    </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        function deletePromoRes(id) {
            swal({
                title: "确定删除？",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true
            },function (){
                $.ajax({
                    type: "post",
                    url: "/backstage/promo/promo-res-del",
                    data:{"id":id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state==1){
                            swal({
                                title:'删除成功！',
                                text: "",
                                type: "success",
                                timer:2000
                            });
                            $('[data-tr-id='+id+']').remove();
                        }else{
                            swal({
                                title: res.message,
                                text: "",
                                type: "error",
                                timer:3000
                            });
                        }
                    },
                    error:function(){
                        swal({
                            title: "系统繁忙！",
                            text: "",
                            type: "error",
                            timer:2000
                        });
                    }
                });//ajax
            });
        }
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        /***
         * 小数格式校验
         * @param num
         * @returns {boolean}
         */
        function checkDecimals(num)
        {
            var reg = /^\d+(?=\.{0,1}\d+$|$)/
            return reg.test(num);
        }
    </script>
@stop